﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TeamCityMonitor.Models;
using TeamCityMonitor.Repository;

namespace TeamCityMonitor.Manager.CustomCreators
{
    public class NotificationCreator : ICustomModelCreator
    {
        private readonly INotificationRepository _notificationRepository;

        public NotificationCreator(INotificationRepository notificationRepository)
        {
            _notificationRepository = notificationRepository;
        }

        public bool IsActive()
        {
            return Properties.Settings.Default.ShowNotifications;
        }

        public List<CustomModel> GetCustomModels()
        {
            var notifications = _notificationRepository.GetAllNotifications();

            var models = new List<CustomModel>();
            notifications.ToList().ForEach(note => models.Add(new CustomModel
                                                            {
                                                                Title = note.Title,
                                                                ImageUrl = note.ImageUrl,
                                                                Footer = note.Text,
                                                            }));
            return models;
        }
    }
}